﻿package Welsy4.Connect.commands
{
	import mx.rpc.events.ResultEvent;
	import mx.rpc.IResponder;
	import mx.controls.Alert;
	
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import Welsy4.Connect.business.CreateUserDelegate;
	import Welsy4.Connect.events.AdobeEvent;
	import Welsy4.Connect.model.ConnectModel;
	import Welsy4.Connect.vo.HttpServiceHandler;
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
	public class CreateMeetingCommand implements Command, IResponder
	{
		
		public function CreateMeetingCommand() 
		{
			
		}
		public function execute(event:CairngormEvent):void {
			var createUserDelegate : CreateUserDelegate = new CreateUserDelegate(this);
			var adobeEvent : AdobeEvent = AdobeEvent (event);
			createUserDelegate.CreateNewUser(adobeEvent.user);
			
			ConnectModel.getInstance().addQueue("CreateUserCommand.execute");
		}
		
		public function result(event:Object):void {
		    ConnectModel.getInstance().addQueue("CreateUserCommand.result");
			
			ConnectModel.getInstance().httpServiceHandler = new HttpServiceHandler();
			ConnectModel.getInstance().httpServiceHandler.setXML(event.result);
			
			
			
			
			if (ConnectModel.getInstance().httpServiceHandler.getResultStatus() == ConnectModel.SESSION_OK) {
			    	
				    Alert.show(ConnectModel.getInstance().httpServiceHandler.xml + "\n\nUser created!!!");
					// dispatchevent user has been created --> a new command for a new era
					
			}
			
		}
		
		public function fault(event:Object):void {
			ConnectModel.getInstance().addQueue("CreateUserCommand.fault");
		}
	}
	
}